package com.csw.shuanfa.SuanFa.huaWei.huaweijikao;

import lombok.extern.slf4j.Slf4j;

import java.util.Scanner;

/**
 * 5 5 HELLOWORLD CPUCY CPUCY CHELL LROWO LROWO 结果3，2
 *
 * @author 1
 */
@Slf4j
public class LianXu {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        log.error("" + "a]" + a);
        String bj = sc.next();
        log.info("" + "bj]" + bj);
        String[] cc = new String[a];
        for (int i = 0; i < a; i++) {
            int line = 0;
            cc[i] = sc.next();
            log.info("" + "cc数组】" + i + "]" + cc[i]);
        }

        int h = -1;
        int l = -1;
        tag2:
        if (h == -1) {
            for (int i = 0; i < bj.length() - 1; i++) {
                log.info("" + "1]" + bj.charAt(i));
                log.info("" + "2]" + bj.charAt(i + 1));
                String qian = String.valueOf(bj.charAt(i)) + bj.charAt(i + 1);
                /* 找到前缀比较 */
                log.info("" + "qian】" + qian);
                for (int j = 0; j < cc.length; j++) {
                    String line = cc[j];
                    /* 每一行的字符串 */
                    log.info("" + "line]" + j + "]" + line);
                    for (int m = 0; m < line.length() - 1; m++) {
                        String hou = String.valueOf(line.charAt(m)) + line.charAt(m + 1);
                        log.info("" + "hou]" + hou);
                        if (qian.equals(hou)) {
                            h = j + 1;
                            l = m + 1;
                            log.info("" + "h]" + h);
                            log.info("" + "l]" + l);
                            break tag2;
                        }
                    }
                }
            }
        }
        if (h != -1) {
            //" + h + " " + l);
        } else {
            log.info("" + "NO");
        }

    }
}
